package com.sskj.fabi.http;


import android.text.TextUtils;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.fabi.bean.FabiBuyBean;
import com.sskj.fabi.bean.FabiListBean;
import com.sskj.fabi.bean.OrderDetailBean;
import com.sskj.fabi.bean.PayWayBean;
import com.sskj.fabi.bean.PublishBean;
import com.sskj.fabi.bean.SysConfigBean;
import com.sskj.lib.bean.PageBean;

import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {

    @Override
    public PostRequest<HttpData<PageBean<FabiListBean>>> getFbList(int page, int size, boolean isBuy) {
        return OkGo.<HttpData<PageBean<FabiListBean>>>post(HttpConfig.BASE_URL + HttpConfig.FABI_LIST)
                .params("page", page)
                .params("pageSize", size)
                .params("tradeType", isBuy ? "2" : "1");
    }

    @Override
    public PostRequest<HttpData<List<PayWayBean>>> getPayList() {
        return OkGo.<HttpData<List<PayWayBean>>>post(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST);
    }

    @Override
    public PostRequest<HttpData> markPay(String entrustNo) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_MARK_PAY)
                .params("orderId", entrustNo);
    }

    @Override
    public PostRequest<HttpData> allegeOrder(String tradeId, String ssType, String mark) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_ALLEGE)
                .params("orderId", tradeId)
                .params("type", ssType)
                .params("reason", mark);
    }

    @Override
    public PostRequest<HttpData> letGo(String tradeId, String tradePwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_LET_GO)
                .params("orderId", tradeId)
                .params("tradePwd", MD5Util.getMd5Value(tradePwd));
    }

    @Override
    public PostRequest<HttpData<PageBean<OrderDetailBean>>> getOrderList(int page, int pageSize, boolean isBuy, String entrustNo) {
        return OkGo.<HttpData<PageBean<OrderDetailBean>>>post(HttpConfig.BASE_URL + HttpConfig.ORDER_LIST_BUY)
                .params("page", page)
                .params("pageSize", pageSize)
                .params("entrustNo", entrustNo)
                .params("tradeType", TextUtils.isEmpty(entrustNo) ? (isBuy ? "1" : "2") : null);
    }

    @Override
    public PostRequest<HttpData> cancelFabiTradeOrder(String orderNum) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_CANCLE)
                .params("orderId", orderNum);
    }

    @Override
    public PostRequest<HttpData<PageBean<PublishBean>>> getFabiPublishOrderList(int page, int pageSize, boolean isBuy, String entrustNo) {
        return OkGo.<HttpData<PageBean<PublishBean>>>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_LIST)
                .params("tradeType", TextUtils.isEmpty(entrustNo) ? (isBuy ? "1" : "2") : null)
                .params("entrustNo", entrustNo)
                .params("page", page)
                .params("pageSize", pageSize);
    }

    @Override
    public PostRequest<HttpData> cancelFabiPublishOrder(boolean isBuy, String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_CANCLE)
                .params("orderId", id)
                .params("tradeType", isBuy ? 1 : 2);
    }

    @Override
    public PostRequest<HttpData<FabiBuyBean>> coinOrder(String tpwd, String order_no, String total_num, String total_price, int isBuy, String payType) {
        return OkGo.<HttpData<FabiBuyBean>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_FABI_ORDER)
                .params("tradePwd", MD5Util.getMd5Value(tpwd))     // 交易密码   委托单号  数量  价钱  出售/求购  id  支付方式
                .params("entrustNo", order_no)  // 委托单号
                .params("transNum", total_num)
                .params("totalPrice", total_price)
                .params("tradeType", isBuy)  // 买卖方向  1买 2 卖
                .params("payType", payType);
    }


    @Override
    public PostRequest<HttpData> createFabiOrder(String type, String sumCount, String lowCount, String hightCount, String unitPrice, String stringBuilder, String pwd) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PUBLISH)
                .params("tradeType", type)  // 交易类型
                .params("minPrice", lowCount)
                .params("maxPrice", hightCount)
                .params("transNum", sumCount)  // 数量
                .params("tradePwd", MD5Util.getMd5Value(pwd))  // 交易密码
                .params("price", unitPrice)  // 估价
                .params("payType", stringBuilder);
    }


    @Override
    public PostRequest<HttpData<List<SysConfigBean>>> getSysConfig(int type) {
        return OkGo.<HttpData<List<SysConfigBean>>>post(HttpConfig.BASE_URL + HttpConfig.SYS_CONFIG)
                .params("type", type);
    }


}